package com.iris.egrant.web.struts2.tags;

import freemarker.template.Configuration;
import freemarker.template.Template;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import java.io.Writer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CheckBoxTag
        extends BodyTagSupport {
    private static final long serialVersionUID = -2769881429877955344L;
    /*  36 */   private String key = "";
    /*  37 */   private String name = "";
    /*  38 */   private String style = "";
    /*  39 */   private String className = "";
    private boolean isLastOther = false;
    /*  41 */   private String otherId = "";
    /*  42 */   private String onClick = "";
    /*  43 */   private String repeatColumn = "1";
    /*  44 */   private String value = "";
    /*  45 */   private String showFlag = "";
    /*  46 */   private String tagType = "checkbox";

    private String otherValueName;

    private String width;
    /*  51 */   private String sqlParamVal = "";


    /*  58 */   private String checked = "none";

    public String getOnClick() {
        /*  61 */
        return this.onClick;
    }

    public void setOnClick(String onClick) {
        /*  65 */
        this.onClick = onClick;
    }


    public int doStartTag() throws JspException {
        /*  70 */
        WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(this.pageContext.getServletContext());

        /*  72 */
        Configuration cptFreemarkereConfiguration = (Configuration) ctx.getBean("cptFreemarkereConfiguration");

        /*  74 */
        if (this.name.trim().length() == 0) {
            /*  75 */
            this.name = this.key;
        }
        /*  77 */
        if (!StringUtils.isNumeric(this.repeatColumn)) {
            /*  78 */
            this.repeatColumn = "1";
        }
        /*  80 */
        Map<String, Object> rootMap = new HashMap<String, Object>();
        /*  81 */
        rootMap.put("id", "checkbox_dyn_" + this.key);

        try {
            /*  84 */
            Template template = cptFreemarkereConfiguration.getTemplate("checkbox.ftl", "utf-8");
            /*  85 */
            if ("".equals(this.showFlag) || "edit".equals(this.showFlag)) {
                /*  86 */
                rootMap.put("content", render());
                /*  87 */
            } else if ("view".equals(this.showFlag)) {
                /*  88 */
                rootMap.put("content", render4view());
                /*  89 */
            } else if ("pdf".equals(this.showFlag)) {
                /*  90 */
                rootMap.put("content", render4pdf());
                /*  91 */
            }
            template.process(rootMap, (Writer) this.pageContext.getOut());
            /*  92 */
        } catch (Exception e) {
            /*  93 */
            throw new JspException(e);
        }

        /*  96 */
        return 0;
    }

//   private BaseComponentService getBaseComponentService() {
///* 100 */     WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(this.pageContext.getServletContext());
//
///* 102 */     ServiceFactory serviceFactory = (ServiceFactory)ctx.getBean("serviceFactory");
//
///* 104 */     return (BaseComponentService)serviceFactory.getService(BaseComponentService.class);
//   }

    private String render() throws Exception {
        /* 108 */
        StringBuffer sb = new StringBuffer();
        /* 109 */
        sb.append("<table class='cbTable' >");
        /* 110 */
        List<Map<String, Object>> result = null;
///* 111 */     BaseComponent baseComponent = getBaseComponentService().findBaseComponentByName(this.key);
///* 112 */     if (!IrisStringUtils.isNullOrBlank(this.sqlParamVal)) {
///* 113 */       Map map = JsonUtils.getMap4Json(this.sqlParamVal);
///* 114 */       baseComponent.getSqlParamVal().putAll(map);
//     }
///* 116 */     if (baseComponent != null) {
///* 117 */       result = getBaseComponentService().findComponentData(baseComponent);
//     }
//

        /* 121 */
        int index = 0;
        /* 122 */
        String otherCbName = this.otherId + "_cb";
        /* 123 */
        int column = Integer.parseInt(this.repeatColumn);
        /* 124 */
        if (result == null) return "";
        /* 125 */
        String tmp_widthString = "width:80px";
        /* 126 */
        if (this.width != null && !"".equals(this.width)) {
            /* 128 */
            if ("none".equals(this.width)) {
                /* 129 */
                tmp_widthString = "";
            } else {
                /* 131 */
                tmp_widthString = "width:" + this.width;
            }
        }
        /* 133 */
        for (int i = 0; i < result.size() &&
                /* 134 */       index < result.size(); i++) {


            /* 137 */
            StringBuffer sbTemp = new StringBuffer("<tr>");
            /* 138 */
            if (column > result.size()) {
                /* 139 */
                column = result.size();
                /* 140 */
            } else if (column > result.size() - index) {
                /* 141 */
                column = result.size() % index;
            }
            /* 143 */
            for (int j = 0; j < column; j++) {
                /* 144 */
                Map<String, Object> data = result.get(index);
                /* 145 */
                if (isLastOther() && index == result.size() - 1) {
                    /* 146 */
                    sbTemp.append("<td align=\"left\" valign=\"top\" colspan='" + (Integer.parseInt(this.repeatColumn) - result.size() % Integer.parseInt(this.repeatColumn) + 1) + "' style='" + tmp_widthString + "'>  <label class='s_rule'  ");
                } else {

                    /* 149 */
                    sbTemp.append("<td align=\"left\" valign=\"top\" nowrap='nowrap'  style='" + tmp_widthString + "' ><label class='s_rule' ");
                }

                /* 152 */
                if ("".equals(this.onClick)) {
                    /* 153 */
                    if (isLastOther() && index == result.size() - 1) {

                        /* 155 */
                        sbTemp.append(" id=\"" + otherCbName + "\"   onclick=\"toogleTextShow('" + otherCbName + "','" + this.otherId + "')\" ");
                        /* 156 */
                    } else if (isLastOther()) {
                        /* 157 */
                        sbTemp.append("   onclick=\"toogleTextShow('" + otherCbName + "','" + this.otherId + "')\" ");
                    }

                    /* 160 */
                } else if (isLastOther() && index == result.size() - 1) {

                    /* 162 */
                    sbTemp.append(" id=\"" + otherCbName + "\"  onclick=\"" + this.onClick + ";toogleTextShow('" + otherCbName + "','" + this.otherId + "')\" ");
                    /* 163 */
                } else if (isLastOther()) {
                    /* 164 */
                    sbTemp.append("   onclick=\"" + this.onClick + ";toogleTextShow('" + otherCbName + "','" + this.otherId + "')\" ");
                } else {

                    /* 167 */
                    sbTemp.append("  onclick=\"" + this.onClick + "(this)\" ");
                }

                /* 170 */
                sbTemp.append(" >  ");
                /* 171 */
                index++;

                /* 173 */
                sbTemp.append("<input type=\"" + this.tagType + "\" ");
                /* 174 */
                if (this.style != null && this.style.trim().length() > 0) {
                    /* 175 */
                    sbTemp.append(" style=\"" + this.style + ";border:none;\" ");
                } else {
                    /* 177 */
                    sbTemp.append(" style=\"border:none;\" ");
                }

                /* 180 */
                if (this.className != null && this.className.trim().length() > 0) {
                    /* 181 */
                    sbTemp.append(" className=\"" + this.className + "\" ");
                }
                /* 183 */
                sbTemp.append("value=\"" + data.get("id") + "\" ");
                /* 184 */
                if (("，" + this.value + "，").indexOf("，" + data.get("id").toString() + "，") != -1) {
                    /* 185 */
                    sbTemp.append("  checked ");
                }
                /* 187 */
                else if (("," + this.value + ",").indexOf("," + data.get("id").toString() + ",") != -1) {
                    /* 188 */
                    sbTemp.append("  checked ");
                }
                /* 190 */
                sbTemp.append("label=\"" + data.get("name").toString().replace(">", "&gt;").replace("<", "&lt;") + "\"");
                /* 191 */
                sbTemp.append(" name=\"" + this.name + "\"/>").append(data.get("name").toString().replace(">", "&gt;").replace("<", "&lt;"));

                /* 193 */
                sbTemp.append("</label>  ");
                /* 194 */
                if (isLastOther() && index == result.size()) {
                    /* 195 */
                    sbTemp.append("    <script type='text/javascript'>  ");
                    /* 196 */
                    sbTemp.append(" setTimeout(\"$('#" + this.otherId + "').insertAfter('#" + otherCbName + "')\",200); ");
                    /* 197 */
                    sbTemp.append(" setTimeout(\"toogleTextShow('" + otherCbName + "','" + this.otherId + "')\",200); ");
                    /* 198 */
                    sbTemp.append("  ");
                    /* 199 */
                    sbTemp.append("  ");
                    /* 200 */
                    sbTemp.append("  ");
                    /* 201 */
                    sbTemp.append("    </script>  ");
                }
                /* 203 */
                sbTemp.append("</td>");
            }
            /* 205 */
            sbTemp.append("</tr>");
            /* 206 */
            sb.append(sbTemp);
        }
        /* 208 */
        sb.append("</table>");

        /* 210 */
        return sb.toString();
    }


    private String render4pdf() throws Exception {
        /* 215 */
        StringBuffer sb = new StringBuffer();
        /* 216 */
        sb.append("<table style='border:0px solid red' class='cbTable'>");
        /* 217 */
        List<Map<String, Object>> result = null;
///* 218 */     BaseComponent baseComponent = getBaseComponentService().findBaseComponentByName(this.key);
///* 219 */     if (!IrisStringUtils.isNullOrBlank(this.sqlParamVal)) {
///* 220 */       Map map = JsonUtils.getMap4Json(this.sqlParamVal);
///* 221 */       baseComponent.getSqlParamVal().putAll(map);
//     }
///* 223 */     if (baseComponent != null) {
///* 224 */       result = getBaseComponentService().findComponentData(baseComponent);
//     }


        /* 228 */
        int index = 0;
        /* 229 */
        String otherCbName = this.name + "_other";
        /* 230 */
        int column = Integer.parseInt(this.repeatColumn);
        /* 231 */
        if (result == null) return "";
        /* 232 */
        String tmp_widthString = "width:100px";
        /* 233 */
        if (this.width != null && !"".equals(this.width)) {
            /* 235 */
            if ("none".equals(this.width)) {
                /* 236 */
                tmp_widthString = "";
            } else {
                /* 238 */
                tmp_widthString = "width:" + this.width;
            }
        }
        /* 240 */
        for (int i = 0; i < result.size() &&
                /* 241 */       index < result.size(); i++) {


            /* 244 */
            StringBuffer sbTemp = new StringBuffer("<tr  style='border:0px solid red;height:10px'>");
            /* 245 */
            if (column > result.size()) {
                /* 246 */
                column = result.size();
                /* 247 */
            } else if (column > result.size() - index) {
                /* 248 */
                column = result.size() % index;
            }

            /* 251 */
            for (int j = 0; j < column; j++) {
                /* 252 */
                Map<String, Object> data = result.get(index);
                /* 253 */
                if (isLastOther() && index == result.size() - 1) {
                    /* 254 */
                    int lastCol = (result.size() % Integer.parseInt(this.repeatColumn) == 0) ? 1 : (Integer.parseInt(this.repeatColumn) - result.size() % Integer.parseInt(this.repeatColumn) + 1);
                    /* 255 */
                    sbTemp.append("<td  style='height:10px;border:0px solid red;" + tmp_widthString + "' align=\"left\" valign=\"top\"   colspan='" + lastCol + "'>  ");
                } else {

                    /* 258 */
                    sbTemp.append("<td  style='height:10px;border:0px solid red;" + tmp_widthString + "' align=\"left\" valign=\"top\" nowrap='nowrap'  >  ");
                }
                /* 260 */
                String mark = "□";
                /* 261 */
                String otherValueNameTempString = "";
                /* 262 */
                if (("，" + this.value + "，").indexOf("，" + data.get("id").toString() + "，") != -1) {
                    /* 263 */
                    mark = "■";
                    /* 264 */
                    if (isLastOther() && index == result.size() - 1) {
                        /* 265 */
                        otherValueNameTempString = "：" + this.otherValueName;
                    }
                    /* 267 */
                } else if (("," + this.value + ",").indexOf("," + data.get("id").toString() + ",") != -1) {
                    /* 268 */
                    mark = "■";
                    /* 269 */
                    if (isLastOther() && index == result.size() - 1) {
                        /* 270 */
                        otherValueNameTempString = "：" + this.otherValueName;
                    }
                }
                /* 273 */
                sbTemp.append(mark).append(data.get("name")).append(otherValueNameTempString);

                /* 275 */
                sbTemp.append("</td>");
                /* 276 */
                index++;
            }
            /* 278 */
            sbTemp.append("</tr>");
            /* 279 */
            sb.append(sbTemp);
        }
        /* 281 */
        sb.append("</table>");

        /* 283 */
        return sb.toString();
    }


    private String render4view() throws Exception {
        /* 288 */
        StringBuffer sb = new StringBuffer();
        /* 289 */
        sb.append("<table class='cbTable' style='border:0px solid red'>");
        /* 290 */
        List<Map<String, Object>> result = null;
///* 291 */     BaseComponent baseComponent = getBaseComponentService().findBaseComponentByName(this.key);
///* 292 */     if (!IrisStringUtils.isNullOrBlank(this.sqlParamVal)) {
///* 293 */       Map map = JsonUtils.getMap4Json(this.sqlParamVal);
///* 294 */       baseComponent.getSqlParamVal().putAll(map);
//     }
///* 296 */     if (baseComponent != null) {
///* 297 */       result = getBaseComponentService().findComponentData(baseComponent);
//     }
//

        /* 301 */
        String tmp_widthString = "width:80px";
        /* 302 */
        if (this.width != null && !"".equals(this.width)) {
            /* 304 */
            if ("none".equals(this.width)) {
                /* 305 */
                tmp_widthString = "";
            } else {
                /* 307 */
                tmp_widthString = "width:" + this.width;
            }
        }
        /* 309 */
        int index = 0;
        /* 310 */
        String otherCbName = this.name + "_other";
        /* 311 */
        int column = Integer.parseInt(this.repeatColumn);

        /* 313 */
        if (result == null) return "";
        /* 314 */
        for (int i = 0; i < result.size() &&
                /* 315 */       index < result.size(); i++) {


            /* 318 */
            StringBuffer sbTemp = new StringBuffer("<tr  style='border:0px solid red'>");
            /* 319 */
            if (column > result.size()) {
                /* 320 */
                column = result.size();
                /* 321 */
            } else if (column > result.size() - index) {
                /* 322 */
                column = result.size() % index;
            }

            /* 325 */
            for (int j = 0; j < column; j++) {
                /* 326 */
                Map<String, Object> data = result.get(index);
                /* 327 */
                if (isLastOther() && index == result.size() - 1) {
                    /* 328 */
                    int lastCol = (result.size() % Integer.parseInt(this.repeatColumn) == 0) ? 1 : (Integer.parseInt(this.repeatColumn) - result.size() % Integer.parseInt(this.repeatColumn) + 1);
                    /* 329 */
                    sbTemp.append("<td  align=\"left\" valign=\"top\"   style='border:0px solid red;word-break: break-all;" + tmp_widthString + "'  colspan='" + lastCol + "'>  ");
                } else {

                    /* 332 */
                    sbTemp.append("<td  align=\"left\" valign=\"top\" nowrap='nowrap'   style='border:0px solid red;word-break: break-all;" + tmp_widthString + "' >  ");
                }

                /* 335 */
                String className = "tu_biao2";
                /* 336 */
                if (("，" + this.value + "，").indexOf("，" + data.get("id").toString() + "，") != -1) {
                    /* 337 */
                    className = "tu_biao1";
                }
                /* 339 */
                else if (("," + this.value + ",").indexOf("," + data.get("id").toString() + ",") != -1) {
                    /* 340 */
                    className = "tu_biao1";
                }
                /* 342 */
                sbTemp.append("<span class='" + className + "'></span> ").append(data.get("name"));
                /* 343 */
                if (isLastOther() && index == result.size() - 1) {
                    /* 344 */
                    sbTemp.append("&nbsp;&nbsp;&nbsp;&nbsp;" + this.otherValueName);
                }
                /* 346 */
                sbTemp.append("</td>");
                /* 347 */
                index++;
            }
            /* 349 */
            sbTemp.append("</tr>");
            /* 350 */
            sb.append(sbTemp);
        }
        /* 352 */
        sb.append("</table>");

        /* 354 */
        return sb.toString();
    }

    public String getKey() {
        /* 358 */
        return this.key;
    }

    public void setKey(String key) {
        /* 362 */
        this.key = key;
    }

    public String getName() {
        /* 366 */
        return this.name;
    }

    public void setName(String name) {
        /* 370 */
        this.name = name;
    }

    public String getStyle() {
        /* 374 */
        return this.style;
    }

    public void setStyle(String style) {
        /* 378 */
        this.style = style;
    }

    public String getRepeatColumn() {
        /* 382 */
        return this.repeatColumn;
    }

    public void setRepeatColumn(String repeatColumn) {
        /* 386 */
        this.repeatColumn = repeatColumn;
    }

    public String getChecked() {
        /* 390 */
        return this.checked;
    }

    public void setChecked(String checked) {
        /* 394 */
        this.checked = checked;
    }

    public String getClassName() {
        /* 398 */
        return this.className;
    }

    public void setClassName(String className) {
        /* 402 */
        this.className = className;
    }

    public String getSqlParamVal() {
        /* 406 */
        return this.sqlParamVal;
    }

    public void setSqlParamVal(String sqlParamVal) {
        /* 410 */
        this.sqlParamVal = sqlParamVal;
    }

    public boolean isLastOther() {
        /* 414 */
        if (this.otherValueName != null && !"".equals(this.otherValueName))
            /* 415 */ this.isLastOther = true;
        /* 416 */
        return this.isLastOther;
    }

    public void setLastOther(boolean isLastOther) {
        /* 420 */
        this.isLastOther = isLastOther;
    }

    public String getOtherId() {
        /* 424 */
        return this.otherId;
    }

    public void setOtherId(String otherId) {
        /* 428 */
        this.otherId = otherId;
    }

    public String getValue() {
        /* 432 */
        return this.value;
    }

    public void setValue(String value) {
        /* 436 */
        this.value = value;
    }

    public String getTagType() {
        /* 440 */
        return this.tagType;
    }

    public void setTagType(String tagType) {
        /* 444 */
        this.tagType = tagType;
    }

    public String getShowFlag() {
        /* 448 */
        return this.showFlag;
    }

    public void setShowFlag(String showFlag) {
        /* 452 */
        this.showFlag = showFlag;
    }

    public String getOtherValueName() {
        /* 456 */
        return this.otherValueName;
    }

    public void setOtherValueName(String otherValueName) {
        /* 460 */
        if (otherValueName != null && !"".equals(otherValueName))
            /* 461 */ this.isLastOther = true;
        /* 462 */
        this.otherValueName = otherValueName;
    }

    public String getWidth() {
        /* 466 */
        return this.width;
    }

    public void setWidth(String width) {
        /* 470 */
        this.width = width;
    }
}


/* Location:              D:\文件kjt\WEB-INF\lib\egrant-core-2.2.20240205.1659.jar!\com\iris\egrant\web\struts2\tags\CheckBoxTag.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */